<template>
	<view>

		<web-view :src="showUrl" style="height: 100vh;"></web-view>
	</view>
</template>

<script>
	import {
		databaseInfo,readDatabase
	} from '@/api/index.js'
	export default {

		data() {
			return {
				page: 1,
				id: null,
				showUrl: '',
				detail:''
			}
		},
		
		async onLoad(options) {
			this.id = options.id
			this.updateNum()
			const token = this.token; // 替换为你的 token
			const id = this.id; // 替换为你的 id 
			const {
				data
			} = await databaseInfo({
				info_id: this.id,
				type: 1
			})
			const name = data.title;
			this.detail=data
			console.log(this.detail,'详情')
			const viewerUrl = 'https://filezl.studylike.top/pdf/web/viewer.html?file=' +
				data.file +
				'&token=' + encodeURIComponent(token) +
				'&id=' + encodeURIComponent(id)+
				'&name=' + encodeURIComponent(name)+
				'&password='+encodeURIComponent(this.systemData.pdf_pwd)+
				'&is_friend='+encodeURIComponent(this.userInfo.is_friend)+
				'&is_encrypted='+encodeURIComponent(data.is_encrypted)

			this.showUrl = viewerUrl
			console.log(this.systemData.pdf_pwd,this.userInfo.is_friend,data.is_encrypted)

		},
		onShareAppMessage(res) {
			
			
				// 来自页面内转发按钮
				return {
					title: this.detail.title,
					path: `/pages/share/share?type=1&id=${this.id}&shareType=friend&database_type=1`,
					imageUrl: this.detail.image
				};
			
		},
		computed: {
			token() {
				return this.$store.state.token
			},
			systemData() {
				return this.$store.state.systemData
			},
			userInfo() {
				return this.$store.state.userInfo
			}

		},
		methods: {
			async updateNum(){
				await readDatabase({database_id:this.id})
			}
		}
	}
</script>

<style scoped lang="scss">
</style>